from bs4 import BeautifulSoup

if __name__ == "__main__":
    fp = open("./file/test.html", "r", encoding="utf-8")
    soup = BeautifulSoup(fp, "lxml")
    # print(soup)
    # print(soup.div)
    # print(soup.a)
    # print(soup.find("div"))
    # print(soup.find("div", class_="song")) # class_/id/attr
    # print(soup.findAll("a"))
    # print(soup.find_all("a"))
    # print(soup.select(".tang > ul > li > a")[0]) # >表示的是一个层级
    # print(soup.select(".tang > ul a")[0]) # 空格表示的多个层级
    # print(soup.div.text) # 可以获取某一个标签中所有的文本内容
    # print(soup.div.get_text()) # 可以获取某一个标签中所有的文本内容
    # print(soup.div.string) # 只可以获取该标签下面直系的文本内容
    # print(soup.select(".tang")[0].text)
    # print(soup.find('div', class_='song').text) # find()返回某个标签、findAll()和select()返回列表
    # print(soup.a['href'])
    # print(soup.select('.tang > ul a')[0]['href'])
    print(soup.select(".tang a")[0]['href'])
